直接進入寫法與範例
const dataList = [5, 7, 10, 99];
const newDataList = dataList.findIndex(function(item){
return item >= 10;
});
console.log(newDataList);
執行結果
const dataList = [
{
goodsName: '帆布提袋',
price: 499
},
{
goodsName: '文青斜背包',
price: 399
},
{
goodsName: '簡約風飲料提袋',
price: 39
},
]
const newDataList = dataList.findIndex(function(item){
return item.price < 200;
});
console.log(newDataList);
console.log(dataList[newDataList]);
執行結果
const dataList = [
{
goodsName: '帆布提袋',
price: 499
},
{
goodsName: '文青斜背包',
price: 399
},
{
goodsName: '簡約風飲料提袋',
price: 39
},
]
const newDataList = dataList.findIndex((item) => {
return item.price < 200;
});
console.log(newDataList);
console.log(dataList[newDataList]);
const dataList = [
{
goodsName: '帆布提袋',
price: 499
},
{
goodsName: '文青斜背包',
price: 399
},
{
goodsName: '簡約風飲料提袋',
price: 39
},
]
const newDataList = dataList.findIndex(item => item.price < 200);
console.log(newDataList);
console.log(dataList[newDataList]);
今天小改了一下箭頭函式的記法,把他當魔法師用的法杖來形容感覺變簡單了!(自以為)
這是我的學習紀錄,有什麼建議和問題都可以跟我說,我們下次見!